﻿namespace Jsl.StyleCop.CSharp
{
    using System;

    public class ViolationInfo : IComparable
    {
        private readonly int lineNumber;
        private readonly string message;

        #region Constructors
        public ViolationInfo(int lineNumber, string message)
        {
            this.lineNumber = lineNumber;
            this.message = message;
        }
        #endregion Constructors

        #region Public Properties
        public int LineNumber
        {
            get { return this.lineNumber; }
        }

        public string Message
        {
            get { return this.message; }
        }
        #endregion Public Properties

        #region Public Methods
        public override int GetHashCode()
        {
            return this.LineNumber;
        }
        #endregion Public Methods

        #region IComparable Members
        public int CompareTo(object target)
        {
            ViolationInfo violation = target as ViolationInfo;
            if (violation != null)
            {
                if (violation.LineNumber != this.LineNumber)
                {
                    return violation.LineNumber - this.LineNumber;
                }

                return string.CompareOrdinal(violation.Message, this.Message);
            }

            return -1;
        }
        #endregion
    }
}